#ifndef SOCKETWRAPPER
#define SOCKETWRAPPER

#include "../logging/logging.h"

class SocketWrapper
{
public:
	static int accept(int fd, struct sockaddr *sa, socklen_t *salenptr);
	static void bind(int fd, const struct sockaddr *sq, socklen_t salen);
	static void connect(int fd, const struct sockaddr *sq, socklen_t salen);
	static void listen(int fd, int backlog);
	static int socket(int family, int type, int protocol);
	static void close(int fd);

	static void shutdown(int fd, int how);
	static int select(int nfds, fd_set *readfds, fd_set *writefds, 
			  fd_set *exceptfds, struct timeval *timeout);
#ifdef  HAVE_POLL
	static int poll(struct pollfd *fdarray, unsigned long nfds, int timeout);
#endif

	static ssize_t recv(int fd, void *ptr, size_t nbytes, int flags);
	static ssize_t recvFrom(int fd, void *ptr, size_t nbytes, int flags,
				struct sockaddr *sa, socklen_t *salenptr);
	static ssize_t recvMessage(int fd, struct msghdr *msg, int flags);

	static void send(int fd, const void *ptr, size_t nbytes, int flags);
	static void sendTo(int fd, const void *ptr, size_t nbytes, int flags,
			   const struct sockaddr *sa, socklen_t salen);
	static void sendMessage(int fd, const struct msghdr *msg, int flags);

	static void setSockOpt(int fd, int level, int optname,
			       const void *optval, socklen_t optlen);

	static int sockAtMark(int fd);
	static void socketPair(int family, int type, int protocol, int *fd);
	static void getPeerName(int fd, struct sockaddr *sa, socklen_t *salenptr);
	static void getSockName(int fd, struct sockaddr *sa, socklen_t *salenptr);
	static void getSockOpt(int fd, int level, int optname, void *optval, socklen_t *optlenptr);

#ifdef  HAVE_INET6_RTH_INIT
	static int inet6RthSpace(int type, int segments);
	static void * inet6RthInit(void *rthbuf, socklen_t rthlen, int type, int segments);
	static void inet6RthAdd(void *rthbuf, const struct in6_addr *addr);
	static void inet6RthReverse(const void *in, void *out);
	static int inet6RthSegments(const void *rthbuf);
	static struct in6_addr* inet6RthGetAddr(const void *rthbuf, int idx);
#endif

private:
	SocketWrapper();
	static logging::Log* _log;
};

#endif /* SOCKETWRAPPER */

